package cn.edu.sjtu.stap.sdg.internal;

import org.aspectj.ajdt.internal.core.builder.AjBuildConfig;

import cn.edu.sjtu.stap.cfg.builder.ICfgBuilder;
import cn.edu.sjtu.stap.cg.builder.ICgBuilder;
import cn.edu.sjtu.stap.sdg.builder.ISdgBuilder;
import cn.edu.sjtu.stap.cfg.internal.*;
import cn.edu.sjtu.stap.cfg.builder.*;
import cn.edu.sjtu.stap.cg.builder.*;
import cn.edu.sjtu.stap.sdg.*;
import cn.edu.sjtu.stap.sdg.builder.ISdgBuilderFactory;
//import cn.edu.sjtu.stap.util.AstArray;

public aspect InterSdgBuilderAdapter {

    after(AjBuildConfig b) : AsmFetcher.asmFetcherPc(b) {
         ICgBuilder cgBuilder = Initializer.getCgBuilder();
         ICfgBuilder cfgBuilder =Initializer.getCfgBuilder();
         ISdgBuilder sdgBuilder =Initializer.getSdgBuilder();
        
         sdgBuilder.buildInterSdg(cgBuilder, cfgBuilder);
        
         // output the SDG
//         SDGResultOutput.getInstance().writeSdg(
//         SDGResultOutput.getFileOutputStream("ResultOfSDG"),
//         sdgBuilder.getSdgs());
         
         Initializer.out.writeLine("InterSDGs Start:------------------------------------------");
         Initializer.out.writeLine("**********************************************************");
         Initializer.out.writeSdg(sdgBuilder.getSdgs());
        
         SDGResultOutput.close();
//         AstArray.getInstance().tidyUp();
    }

//    private static ICgBuilder getCgBuilder() {
//        return ICgBuilderFactory.getDefaultCgBuilderFactory().getCgBuilder();
//    }
//
//    private static ICfgBuilder getCfgBuilder() {
//        return ICfgBuilderFactory.getDefaultCfgBuilderFactory().getCfgBuilder();
//    }

    private static ISdgBuilder getSdgBuilder() {
        return ISdgBuilderFactory.getDefaultSdgBuilderFactory().getSdgBuilder();
    }
}
